Learning Objectives

After completing this lesson, you’ll be able to:

Resources

Note

All resources are available via the links above. If you are using a Safe Software training machine or downloaded FMEData, you can use the local paths.

Video

Introduction

You have recently created an Automation in FME Flow that processes building footprint updates with both the Resource or Network Directory (updated) and Email Triggers. The Automation monitors a Shared Resource Data folder on FME Flow for new building footprint shapefiles, then adds the updates to a SpatiaLite database automatically. Now your supervisor is wondering if they can receive a notification whenever the corporate database is updated.

You know it is possible to configure the existing Automation in FME Flow to satisfy this requirement. You also realize that you can use an Automations writer in the workspace to include additional information about the updates made to the corporate database in the notification.

Note

This is a great use-case for the Email External Action. However, those can be a bit tricky to configure due to email server security.

Therefore, for simplicity's sake, in this exercise, we will just use the Log a Message Action in place of the Email External Action.

If you are interested in learning how to use an email with Automations, please refer to the Run Workspaces with Email Triggers lesson.

1) Open Workspace in Workbench

Open the starting workspace template (C:\FMEData\Workspaces\AutomateWorkflows\exercise-use-the-automations-writer.fmwt)in FME Workbench (2023.0 or later).

2) Create Summary Information for a Job

You are going to update this workspace to generate a summary of the number of records that were updated from the incoming Shapefile. First, you need to create a single feature from the updates. This step is common in FME when you want to log a summary message; you just want to log one per update, not one for every feature in that update. 

Add an Aggregator transformer and connect it in parallel to the Shapefile reader feature type like this:

Starting workspace with Aggregator added


Open the Aggregator parameters dialog and set the Accumulation Mode to “Use Attributes From One Feature” and the Number of Aggregated Features to be named NumberOfUpdates.

3) Add Automations Writer

Go to Writers > Add Writer and select the FME Flow Automations format. Set the Feature Type Definition to Automatic... and click OK to add the writer to the canvas. 

When prompted, set the Feature Type Name to JobSummary and click OK.

Connect the Automations writer feature type to the output port of the Aggregator transformer.

Each Automation writer feature type will appear as a new output port on your Run a Workspace Action in your Automation.

4) Clean up Automations Writer Attributes

After connecting the Automations writer feature type, you'll notice that all the attributes from the Shapefile data are included on the writer. We don't need all that information within the Automation. Double-click JobSummary to open its parameter dialog, then go to User Attributes and select Manual under Attribute Definition.

Remove all the attributes except for the one we created earlier, NumberOfUpdates. Set the Type for NumberOfUpdates to int, as this is a numeric value.

Setting User Attributes

Click OK to apply that change. At this stage, there should be two attributes on the JobSummary Feature Type: NumberOfUpdates and fme_feature_type.

Connecting Aggregator to new JobSummary writer feature type

5) Save and Publish Workspace

Save the workspace.

Select File > Publish it to FME Flow. 

Choose your FME Flow Connection to use. Click Next.

Use the Training Repository (click New... and create it if it doesn't exist). Check Upload data files. Click Next.

Ensure only the Job Submitter service is checked. Click Publish.

6) Import FME Flow Project

We need to import the Automation you've already created that checks for building updates.

Download the project here (C:\FMEData\Workspaces\AutomateWorkflows\exercise-use-the-automations-writer.fsproject)

Open the FME Flow web interface and navigate to the Projects > Manage Projects page. 

Manage Projects button

Click the Import button, ensure Import From is set to Upload, then click Upload File, and select the project you just downloaded. Once you've selected it, click Import. A new Automation will be uploaded to your FME Flow.

7) Update Workspace Action

Navigate to Automations > Manage Automations. Click the new Incoming Building Footprints Automation to edit it. 

You can see that this Automation starts with either a Resource or Network Directory (updated) Trigger with a Filter Action or an incoming Email (SMTP) Trigger. On success, both streams run the RealTime-Ex2-Complete.fmw workspace. We need to update this Action to use our new workspace.

Click on the Workspace Action in the Automation to open its parameters. Change the Workspace parameter to your recently published workspace. 

Set the Source Esri Shapefile(s) parameter to the Custom Attributes {user.shapefile} and set the SpatialLite Database path to $(FME_SHAREDRESOURCE_DATA)/Output/building_footprints.sl3 (the existing destination SpatialLite database we just added using the Flow Project). 

Click Apply.

Setting Shapefile and Spatialite parameters

A new output port named JobSummary should appear in the Automation, created by the Automation Writer we just added to the workspace:

JobSummary port

8) Add External Action

The final step in the Automation is to add a Log a Message Action through which a response will be sent.

Select the plus icon in the bottom left and drag an Action (orange) to the canvas. Connect this to the JobSummary output port of the Run Workspace node, which will now also act as a Trigger.

Adding an Action

Click the FME Flow logo on Action to open its parameters. Choose Log a message for the Action. Enter the following for the Formatted Message:

The Building Footprints database has been updated! {route.JobSummary.NumberOfUpdates} records were updated.

If you prefer, you can enter this manually using the Text Editor. You can access it by clicking the drop-down arrow next to Formatted Message and clicking Text Editor:

Setting the Formatted Message using the Text Editor

Similar to the Text Editor in FME Workbench, you can construct values using the tree of keys on the left. 

The Text Editor in Automations

After entering in your Formatted Message, click Apply.

Note

If you were using an Email Action, this message could be the body of the email.

Save and start your Automation.

9) Test Automation

We can test this Automation by uploading this ZIP file (C:\FMEData\Data\Engineering\BuildingFootprints) of the Shapefile datasets to FME Flow's Shared Resources Data folder. The Automation is monitoring this folder; when new files arrive, it will run the workspace, updating the SpatiaLite database building_footprints.sl3. We should be able to see this process by examining the Automation log.

To upload the ZIP file, first, download it. 

Then, extract it to a folder called BuildingUpdates.

Then navigate to Resources using the FME Flow web interface. Then click on Data.

Find the shared Data folder

Create (or open if it already exists) the BuildingUpdates folder. Click it to view its contents.

Next, click the Upload button and then click Files.

Uploading files

Select the four files corresponding to one of the updates (e.g., update002.dbf, update002.prj, update002.shp, and update002.shx) and click Upload, and then OK. The SHP update will be uploaded.

Click Automations > Manage Automations > Incoming Building Footprints. Click Menu > View Triggered Jobs. You should see a job for the new building update. If you upload another four files or upload multiple updates at once, you should see one job for each update.

Viewing jobs

Note

The polling interval for the Resource or Network Directory (updated) trigger is set to 30 seconds, so it can take a moment for these Jobs to appear.

If you examine the Automation log (Automations > Manage Automations > Incoming Building Footprints > Menu > View Log), you should see one line like this per job:

2022-08-27T10:57:04-07:00 | The Building Footprints database has been updated! 44 records were updated.

Congratulations! You have successfully used the Automations writer to pass messages out of a workspace.